package com.jvm.interpreter.instruction;

import com.jvm.classfile.model.CpInfo;
import com.jvm.interpreter.Frame;
import com.jvm.interpreter.Instruction;

/**
 * @program: diy_simple_jvm
 * @description: bipush指令
 * @author: CaoYong
 * @create: 2021-07-08 13:33
 **/
public class BiPushInst implements Instruction {

    public final int val;

    public BiPushInst(int val) {
        this.val = val;
    }

    /**
     * 将制定参数推到操作数栈的栈顶
     * @param frame 栈帧
     */
    @Override
    public void eval(Frame frame) {
//        frame.operandStack.push(val);
        frame.pushInt(val);
        frame.pc += offset();
    }

    @Override
    public int offset() {
        return 2;
    }

    static BiPushInst parse(java.io.DataInputStream dis, CpInfo[] cp) throws java.io.IOException {
        return new BiPushInst(dis.readByte());
    }
}
